package com.typing.battle.activity;

import com.typing.battle.R;
import com.typing.battle.view.TimeAttackListView;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.LinearLayout;

public class TypingBattleTimeAttackListActivity extends Activity{
	private TimeAttackListView listView;
	private LinearLayout layout,progressLayout;
	@Override
    protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        setContentView(R.layout.battle_time_attack_list);
        layout = (LinearLayout)findViewById(R.id.layout_time_attack_list);
        listView = new TimeAttackListView(this);
        progressLayout = (LinearLayout) View.inflate(this, R.layout.battle_list_progress, null);
    	progressLayout.setVisibility(View.INVISIBLE);
    	listView.addFooterView(progressLayout);
        listView.setOnScrollListener(new OnScrollListener() {
	
			// @Override
			public void onScrollStateChanged(AbsListView view, int scrollState) {
				// TODO Auto-generated method stub
				
			}
			
			// @Override
			public void onScroll(AbsListView view, int firstVisibleItem,
					int visibleItemCount, int totalItemCount) {
				// TODO Auto-generated method stub
				
				if ((firstVisibleItem + visibleItemCount) == totalItemCount) {
					Log.v("list", "IN, totalItemCount = " + totalItemCount);
					
					if (listView.getTotalCount() > listView.getCurrentIndex()) {
						progressLayout.setVisibility(View.VISIBLE);
						listView.getNextList();
					} else {
						progressLayout.setVisibility(View.INVISIBLE);
					}
					
				}
			}
		});        

        layout.addView(listView);
	}
	@Override
    protected void onResume() {
    	// TODO Auto-generated method stub
		listView.refreshData();
    	super.onResume();
    }
}
